{include file="../_meta" /}
<body style="padding:0px;">
<!-- 添加用户窗口-->
<style>
	form {
		padding:20px 40px;
	}
</style>
<!-- 
<script src="/static/jqueryfileupload/js/jquery.iframe-transport.js"></script>	
<script src="/static/jqueryfileupload/js/jquery.fileupload.js"></script>	
<script src="/static/jqueryfileupload/js/jquery.fileupload-jquery-ui.js"></script>	
<script src="/static/jqueryfileupload/js/jquery.fileupload-process.js"></script>	 -->


<!-- The jQuery UI widget factory, can be omitted if jQuery UI is already included -->
<script src="/static/jqueryfileupload/js/jquery.ui.widget.js"></script>
<!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
<script src="/static/jqueryfileupload/js/jquery.iframe-transport.js"></script>
<!-- The basic File Upload plugin -->
<script src="/static/jqueryfileupload/js/jquery.fileupload.js"></script>



<form id="ff" class="easyui-form" method="post"  enctype="multipart/form-data">

	<div style="margin-bottom:20px">
		<div style="margin-bottom:2px">上传批次: <span style="color:#F00;">上传批次是上传文件的标识,可不填写.</span></div>
		<input class="easyui-textbox" name="import_no" style="width:100%">
	</div>
	<div style="margin-bottom:10px">
		<div  style="margin-bottom:2px">上传Excel文件:</div>
		<input class="easyui-filebox" name="importFile" data-options="prompt:'选择一个文件进行上传',buttonText:'选择文件'" style="width:100%" multiple>
	</div>
	<div style="margin-bottom:10px" id="uploadList">
		<input type="hidden" id="filesName" name="filesName" value=""/>
		<input type="hidden" id="filesPath" name="filesPath" value=""/>

	</div>
	<div style="margin-bottom:20px">
		<div  style="margin-bottom:2px">备&emsp;&emsp;注:</div>
		<input class="easyui-textbox" name="memo" style="height:70px;width:100%;" data-options="multiline:true">
	</div>
	<div style="text-align:center;">
		<a href="#" class="easyui-linkbutton" onclick="save();" style="width:30%;margin-right:20px;">上 传</a>
		<a href="#" class="easyui-linkbutton" onclick="javascript:Close();" style="width:30%">取 消</a>
	</div>
	
</form>	

	
<script type="text/javascript">
$(function(){
	$('#importFile').filebox({
		accept: 'text/csv;application/vnd.ms-excel;',
		multiple:true
	});
});

$(function () {

	$('#filebox_file_id_1').fileupload({
		dataType: 'json',
		url:'excelUpload',
		done: function (e, data) {
			<!-- data.context.text('Upload finished.'); -->
			//console.info(data.result)
			if(data.result.status) {			
				var name = data.result.files.name;
				var path = data.result.files.savaPath;				
				$('<p/>').html(name +"<span style='margin-left:10px;font-size:13px;color:red;'>上传成功</span>").appendTo('#uploadList');
				
				var no = $('#filesName').val();
				var po = $('#filesPath').val();
				
				if(!isEmpty(no)) {
					var nn = no+','+name;
				} else {
					var nn = name;
				}
				$('#filesName').val(nn);

				if(!isEmpty(po)) {
					var pn = po+','+path;
				} else {
					var pn = path;
				}
				$('#filesPath').val(pn);	
			} else {
				parent.$.messager.show({
							title: "文件上传失败,请联系系统技术人员",
							msg:  data.result.errMsg
				});
			}

		}
	});
	
});
	
// 判断JS变量是否为空
function isEmpty(data){ 
	return (data == "" || data == undefined || data == null || data.length == 0) ? true : false; 
}

// 关闭此窗口
function Close() {
	var no = $('#filesName').val();		
	if(!isEmpty(no)) {		
		parent.$.messager.confirm('关闭确认','您已上传文件, 确定放弃它们?',function(r){
			if (r){
				parent.$('#dlg').dialog('close');
			} else {
				return false;
			}
		});
	} else {
		parent.$('#dlg').dialog('close');
	}
}


// 保存用户
function save() {
	$('#ff').form('submit',{
		url: "excelSave",
		onSubmit: function(){
			return $(this).form('enableValidation').form('validate');
		},
		success: function(result) {			
			var result = eval('('+result+')');
			if (result.errorMsg){
				parent.$.messager.show({
					title: 'Error',
					msg: result.errorMsg
				});
			} else {				
				
				parent.$.messager.show({
					title: 'Success',
					msg:  result.msg,
				});
	
				parent.$('#dlg').dialog('close')
				parent.$('#easyui_dg').datagrid('reload');	// reload the user data
			}
		}
	});
};
</script>

				
</body>
</html>